// hyb_yl/krecovery/pages/followUp_editTime/followUp_editTime.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    interval_days: ['1天', '2天', '3天', '4天'],
    days: "",
    id: "",
    list: [],
    edit_state: false,
    followUp_TimeList: [
      {
        time: "2021-12-12",
        name: "张三",
        interval: "1天",
      }
    ]
  },
  choose_time: function (e) {
    console.log(e.detail)
    this.setData({
      folloewUptime: e.detail.value,
      days: e.detail.value
    })
  },
  choose_interval: function (e) {
    console.log(e.detail.value)
    var interval_days = this.data.interval_days
    this.setData({
      interval_text: interval_days[e.detail.value]
    })
  },
  name_input: function (e) {
    console.log(e.detail.value)
    this.setData({
      patient_name: e.detail.value
    })
  },
  edit_show: function (e) {
    var state = e.currentTarget.dataset.state;
    var index = e.currentTarget.dataset.index;
    this.setData({
      state: state,
      edit_state: true,
      edit_index: index,
      info: that.data.list[index],
      id: e.currentTarget.dataset.id,
      days: info.days
    })
  },

  closezhe: function () {
    this.setData({
      edit_state: false
    })
  },
  complete: function (e) {
    var state = e.currentTarget.dataset.state;
    var edit_index = this.data.edit_index;
    var followUp_TimeList = this.data.followUp_TimeList;
    if (state == 1) {
      followUp_TimeList.push({
        time: this.data.folloewUptime,
        name: this.data.patient_name,
        interval: this.data.interval_text,
      })
    } else if (state == 2) {
      followUp_TimeList[edit_index].time = this.data.folloewUptime;
      followUp_TimeList[edit_index].name = this.data.patient_name;
      followUp_TimeList[edit_index].interval = this.data.interval_text;
    }
    this.setData({
      followUp_TimeList: followUp_TimeList,
      edit_state: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var back_orser = options.back_orser;
    var j_id = options.j_id;
    that.setData({
      back_orser: back_orser,
      j_id: j_id,
      names: options.names,
      telphone: options.telphone,
      back_orser: options.back_orser,
      numcard: options.numcard,
      sex: options.sex,
      openid: options.openid
    })
    that.getSuifang();
  },
  back: function (e) {
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2];
    prevPage.setData({
      days: e.currentTarget.dataset.days,
    })
    wx.navigateBack({
    })
  },
  getSuifang: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/green.get_suifang",
      data: {
        zid: that.data.zid,
        j_id: that.data.j_id,
      },
      success: function (res) {
        that.setData({
          list: res.data
        })
      }
    })
  },
  // 修改随访
  edit: function () {

    var that = this;
    app.util.request({
      'url': "entry/wxapp/green.edit_suifang",
      data: {
        id: that.data.id,
        days: that.data.days
      },
      success: function (res) {
        that.getSuifang();
      }
    })
  },
  // 删除随访
  del: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.showModal({
      cancelColor: '提示',
      content: "是否删除该记录",
      success: function (con) {
        if (con.confirm) {
          app.util.request({
            'url': "entry/wxapp/green.del_green",
            data: {
              id: id
            },
            success: function (res) {
              that.getSuifang();
            }
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})